<?php
class mis_penugasan_teknisi_model extends MY_Model {
	var $nama_tabel = 'ADMIN_PRIMKOKAS.TBLBARANG';
	
	function GetJSON() {
		$ls_sql	= "	SELECT	*
					FROM	".$this->nama_tabel." 
					WHERE	(UPPER(KODEBARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NAMABARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NAMA) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(STATUS) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(TIPE) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'KODEBARANG' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );

	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.TBLBARANG WHERE KODEBARANG = '".$arr_rule['kodebarang']."'"))<1)
			{
				return $this->error_delete.' [id: '.$arr_rule['KODEBARANG']."]<br /> SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.TBLBARANG WHERE KODEBARANG = '".$arr_rule['kodebarang']."'";
			}else{
				$this->db->delete('ADMIN_PRIMKOKAS.TBLBARANG', array('kodebarang' => $arr_rule['kodebarang']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

}
?>